<template>
	<view class="page">
		<scratch-card ref="scratchCardRef" :width="300" :height="200" :prizeName="prizeInfo.prizeName"
			:bgSrc="prizeInfo.bgSrc" :prizeEnd="prizeInfo.prizeEnd" @success="scrapingSuccess" @start="startPlay" />

	</view>

</template>

<script>
	import ScratchCard from '@/components/scratch-card/index.vue'
	export default {
		components: {
			ScratchCard
		},
		data() {
			return {
				prizeInfo: {
					prizeEnd: false,
					prizeName: 'iphone',
					bgSrc: 'https://imgurl.haiminglan.cn/8d9aee1b4843f05d5006b79a37c1aad831e6133669167dcd380bb974011b2455.jpeg'
				},
				luckDrawInfo: {
					start_time: '2024-06-10',
					end_time: '2024-09-10'
				}
			}
		},
		props: {

		},
		onLoad() {
			this.$nextTick(() => {
				this.inits();
			})
		},
		methods: {
			inits() {
				this.$refs.scratchCardRef.init()
			},
			startPlay() {
				// 活动未开始或活动已结束
				let startTimeMs = new Date(this.luckDrawInfo.start_time).getTime();
				let endTimeMs = new Date(this.luckDrawInfo.end_time).getTime();
				let nowTimeMs = new Date().getTime();
				if (nowTimeMs < startTimeMs) {
					uni.showToast({
						icon: "none",
						title: "活动未开始"
					})
					this.prizeInfo.prizeEnd = true;
				} else if (nowTimeMs > endTimeMs) {
					uni.showToast({
						icon: "none",
						title: "活动已结束"
					})
					this.prizeInfo.prizeEnd = true;
				} else {
					this.prizeInfo.prizeEnd = false;
				}
			},
			scrapingSuccess() {
				uni.showModal({
					title: '温馨提示',
					success: (res) => {
						this.$refs.scratchCardRef.drawInit()
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">

</style>